package com.yangcangclub.trade.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yangcangclub.trade.bean.TradeSummary;
import com.yangcangclub.trade.bean.TradeVo;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

/**
 * Created by user on 2017/2/24.
 */
public interface TradeService {
    /**创建订单
     * @param totalPrice
     * @param userId
     * @param productList
     * @param payType
     * @param source
     * @param province
     * @param city
     * @param county
     * @param contactName
     * @param contactMobile
     * @param contactAddress
     * @param expressId
     * @param userRemark
     * @param addressId
     * @return
     * @throws Exception
     */
    public Map<String, Object> buy(String totalPrice, int userId, JSONObject productList, String payType,
                                   String source, String province, String city, String county,
                                   String contactName, String contactMobile, String contactAddress,
                                   int expressId, String userRemark, int addressId) throws Exception;
    /**更新订单
     * @param updateType    :express（物流）,contact（收件人信息）,other（其他信息 客服备注）
     * @param id
     * @param updateInfo
     * express-->expressName,expressId,expressNo
     * contact-->province,city,county,contactName,contactMobile,contactAddress
     * other-->serviceRemark
     * @param updateUserId
     * @return
     * @throws Exception
     * */
    public boolean updateTrade(String updateType, int id, JSONObject updateInfo, int updateUserId)throws Exception;

    /**更新订单状态
     * @param userId
     * @param id
     * @param status
     * S待付款[创建订单后默认状态]D待发货[由支付成功异步回调实现]R已发货[由updateTrade方法实现]
     * E已完成[由本方法实现]C已取消[由本方法实现]
     * F已退款[由本方法实现,暂不操作]
     * @return
     * @throws Exception
     */
    public boolean updateTradeStatus(int userId,int id, String status)throws Exception;

    /**更新订单状态
     * @param id
     * @param status
     * S待付款[创建订单后默认状态]D待发货[由支付成功异步回调实现]R已发货[由updateTrade方法实现]
     * E已完成[由本方法实现]C已取消[由本方法实现]
     * F已退款[由本方法实现,暂不操作]
     * @param serviceRemark 客服备注[后台取消订单、退款订单 必须备注原因]
     * @param updateUserId
     * @return
     * @throws Exception
     */
    public boolean updateTradeStatus(int id, String status, String serviceRemark,int updateUserId)throws Exception;

    /**获取订单列表（api）
     * @param pageNum
     * @param pageSize
     * @param orderBy
     * @param map
     * @return
     * @throws Exception
     */
    public Map<String, Object> getTradeList(int pageNum, int pageSize, String orderBy,
                             Map map) throws Exception;

    /**获取订单列表（后台）
     * @param start
     * @param pageSize
     * @param map
     * @return
     */
    public Map<String, Object> getManagerTradeList(int start, int pageSize,Map map);

    /**获取订单详细（api）
     * @param userId
     * @param id
     * @return
     * @throws Exception
     */
    public TradeVo getTradeDetailsById(int userId, int id) throws Exception;

    /**获取订单id（后台）
     * @param id
     * @return
     * @throws Exception
     */
    public TradeVo getTradeDetailsById(int id) throws Exception;

    /**根据订单号获取订单信息
     * @param tradeNo
     * @return
     * @throws Exception
     */
    public TradeVo getTradeDetailsByTradeNo(String tradeNo) throws Exception;

    /**支付宝支付成功异步通知
     * @param map
     * @return
     * @throws UnsupportedEncodingException
     * */
    public boolean tradeAlipayNotify(Map<String, String> map) throws UnsupportedEncodingException;

    /**微信支付成功异步通知
     * @param map
     * @return
     * @throws UnsupportedEncodingException
     */
    public boolean tradeWechatNotify(Map<String, String> map) throws UnsupportedEncodingException;

    /**继续支付
     * @param userId
     * @param tradeId
     * @param payType
     * @return
     * @throws Exception
     */
    public Map<String, Object> continuePay(int userId,int tradeId,String payType) throws Exception;

    /**查询超时订单
     * @param time
     * @return
     */
    public List<TradeSummary> selectPayTimeOutTrades(int time);

    /**取消超时订单
     * @param tradeId
     * @param tradeNo
     * @return
     */
    public boolean cancelPayTimeOutTrades(int tradeId,String tradeNo);
    /**查询订单状态及支付状态*/

}
